using System.Collections;
using UnityEngine;
using UnityEngine.Audio;

public class Audio : MonoBehaviour
{
	public static Audio instance;

	public AudioMixer masterMixer;

	public AudioSource[] music;

	public AudioSource[] ui;

	public AudioSource[] sfxLoop;

	public AudioSource[] sfx;

	private int rnd;

	public float musicVolume { get; set; }

	public float sfxVolume { get; set; }

	private void Awake()
	{
		if (instance != null)
		{
			Object.Destroy(base.gameObject);
		}
		else
		{
			instance = this;
		}
	}

	private IEnumerator Preload()
	{
		float[] volList = new float[sfx.Length];
		for (int i = 0; i < sfx.Length; i++)
		{
			volList[i] = sfx[i].volume;
			sfx[i].volume = -80f;
			sfx[i].Play();
		}
		yield return new WaitForSeconds(2f);
		for (int j = 0; j < sfx.Length; j++)
		{
			sfx[j].volume = volList[j];
		}
	}

	public void AllStopLoopSfx()
	{
		for (int i = 0; i < sfxLoop.Length; i++)
		{
			sfxLoop[i].Stop();
			sfxLoop[i].mute = false;
		}
	}

	public void AllPauseLoopSfx(bool pause)
	{
		for (int i = 0; i < sfxLoop.Length; i++)
		{
			if (pause)
			{
				sfxLoop[i].mute = true;
			}
			else if (!pause)
			{
				sfxLoop[i].mute = false;
			}
		}
	}

	public void MusicSwitch(string swt)
	{
		masterMixer.SetFloat("MusicVol", (swt == "off") ? (-80) : 0);
		PlayerPrefs.SetString("MusicVol", swt);
	}

	public void SfxSwitch(string swt)
	{
		masterMixer.SetFloat("SfxVol", (swt == "off") ? (-80) : 0);
	}

	public void PlayWeaponSFX(int kindOfWeapon)
	{
		switch (kindOfWeapon)
		{
		case 0:
			rnd = Random.Range(0, 5);
			break;
		case 1:
			rnd = Random.Range(16, 21);
			break;
		case 2:
			rnd = Random.Range(16, 21);
			break;
		case 3:
			rnd = Random.Range(16, 21);
			break;
		case 4:
			rnd = Random.Range(0, 5);
			break;
		case 5:
			rnd = Random.Range(38, 38);
			break;
		case 6:
			rnd = Random.Range(16, 21);
			break;
		}
		sfx[rnd].Play();
	}
}
